<?php
	class Model_room extends CI_Model{
		protected $_table = "tbl_rooms";
		protected $_cruise = "tbl_cruises";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function count_all(){
			$this->db->join("tbl_cruises","tbl_cruises.cruise_id = tbl_rooms.cruise_id");
			return $this->db->count_all_results($this->_table);
		}
		public function list_all($off,$start){
			$this->db->join("tbl_cruises","tbl_cruises.cruise_id = tbl_rooms.cruise_id");
			$this->db->limit($off,$start);
			return $this->db->get($this->_table)->result_array();
		}
		public function listall(){
			$this->db->join("tbl_cruises","tbl_cruises.cruise_id = tbl_rooms.cruise_id");
			return $this->db->get($this->_table)->result_array();
		}
		public function listship(){
			$this->db->order_by("cruise_name");
			return $this->db->get($this->_cruise)->result_array();
		}
		public function add($data){
			$this->db->insert($this->_table,$data);
		}
		public function update($data,$id){
			$this->db->where("room_id",$id);
			$this->db->update($this->_table,$data);
		}
		public function getdata($id){
			$this->db->where("room_id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function del($id){
			$this->db->where("room_id",$id);
			$this->db->delete($this->_table);
		}
		public function listroom($ship_id){
			$this->db->join("tbl_cruises","tbl_cruises.cruise_id = tbl_rooms.cruise_id");
			$this->db->where("tbl_rooms.cruise_id",$ship_id);
			return $this->db->get($this->_table)->result_array();
		}
	}